/*
*
==============================================================================
*  Name        : 
*  Part of     : Omen Game Engine - OpenGL Plugin
*  Description : 
*  Version     : 1.0
*
*  Copyright (c) 2013 Lauri Kortevaara.
* 
==============================================================================
*/

#ifndef _OPENGL_PLUGIN_H_
#define _OPENGL_PLUGIN_H_

///////////////////////////////////////////////////////////////////////////////
// Omen Game Engine class                                               //
//                                                                           //
//                                                                           //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
#define OPENGLPLUGIN_SOURCE 1

#include "Config.h"

#include <IOmenKernel.h>
#include <IOmenRenderer.h>
#include <IOmenGraphicsDriver.h>
#include <IOmenGraphicsServer.h>

#include "OpenGLWindow.h"

#include <iostream>

using namespace std;

namespace Omen {

  /// OpenGL renderer
  class OpenGLRenderer : public Omen::IRenderer
  {
    #define GUID_OPENGL_PLUGIN "1DE79F64-5DAE-4827-81A7-F5D674B71C3E"

    public:
        virtual Omen_GUID classId() const { return OMEN_UUID(GUID_OPENGL_PLUGIN); }    /// <summary>Defines the class ID</summary>

        OpenGLRenderer();

        /// Vertex and Index buffer interface of IOmenRenderer
        virtual void createVertexBuffer( IMesh* pMesh ) const; /// <summary>Renderer creates a vertex buffer for this mesh</summary>
        virtual void createIndexBuffer( IMesh* pMesh ) const;  /// <summary>Renderer creates an index buffer for this mesh</summary>

        /// Shader creation
        virtual bool createShader( const std::wstring& shaderName, Omen::IShader*& pShader ) const ; /// <summary>Create a shader with given name</summary>

        /// Rendering interface of IOmenRenderer
        virtual unsigned long windowHandle(void) const;
      
        virtual void beginRendering() const ;
        virtual void render(Omen::ICamera* pCamera) const;
        virtual void render(Omen::ILight** pLights, unsigned int numLights) const;
        virtual void render(Omen::IModel** pCameras, unsigned int numModels) const;
        virtual void endRendering() const;


       OpenGLWindow      m_window;
  };

  /// OpenGL graphics drver
  class OpenGLGraphicsDriver : public Omen::IGraphicsDriver
  {

    public: 
        /// <summary>Creates an OpenGL graphics driver</summary>
        OPENGLPLUGIN_API OpenGLGraphicsDriver();
        /// <summary>Destroys an OpenGL graphics driver</summary>
        //OPENGLPLUGIN_API virtual ~OpenGLGraphicsDriver();

        /// <summary>Gets the name of the graphics driver</summary>
        virtual const std::wstring &getName() const;

        void operator()() const; // Slot

        void setActive( const bool &bActive ) { m_bIsActive = bActive; }

        /// <summary>Creates a renderer</summary>
        Omen::IRenderer* createRenderer();

    protected:
        void initialize();

  private:
      bool                      m_bIsActive;
      OpenGLRenderer*           m_renderer;
  };

  /// <summary>Retrieve the engine version we're going to expect</summary>
  extern "C" OPENGLPLUGIN_API int getEngineVersion() { return 1; }

  /// <summary>Register the plugin to an engine kernel</summary>
  /// <param name="kernel">Kernel the plugin will register to</summary>
  extern "C" OPENGLPLUGIN_API void registerPlugin(Omen::IKernel* kernel) {
    kernel->getGraphicsServer()->addGraphicsDriver(new OpenGLGraphicsDriver());
  }

} // namespace Omen

#endif // _OPENGL_PLUGIN_H_